import { MockMethod } from 'vite-plugin-mock'
import RouteList from '@/assets/json/routerList.json'
import ButtonList from '@/assets/json/authButton.json'

export default [
  {
    // 获取用户信息的接口
    url: '/api/getUserInfo',
    method: 'get',
    response: () => {
      return {
        code: 200,
        message: '获取成功',
        data: {
          routes: '',
          roles: 'admin',
          nickname: 'aurora'
        }
      }
    }
  },
  {
    url: '/api/login',
    method: 'post',
    // 使用 body 可以获取请求体
    response: ({ body }) => {
      if (body.username === 'error') {
        // 返回JSON信息
        return {
          code: 201,
          message: '密码错误',
          data: {
            access_token: ''
          }
        }
      }
      // 其余的则显示登录成功
      if (body.username === 'admin') {
        return {
          code: 200,
          message: '登录成功',
          data: {
            access_token: 'admin'
          }
        }
      } else {
        return {
          code: 200,
          message: '登录成功',
          data: {
            access_token: 'common'
          }
        }
      }
    }
  },
  {
    url: '/api/logout',
    method: 'post',
    response: () => {
      return {
        code: 200,
        message: '退出成功',
        data: {
          accessToken: ''
        }
      }
    }
  },
  {
    url: '/api/menu/list',
    method: 'get',
    response: () => {
      return {
        code: 200,
        message: '',
        data: RouteList.data
      }
    }
  },
  {
    url: '/api/button/list',
    method: 'get',
    response: () => {
      return {
        code: 200,
        message: '',
        data: ButtonList.data
      }
    }
  },
] as MockMethod[]
